package com.phychips.rcp;

import com.phychips.common.*;
import com.phychips.serial.*;

public class SerialIo extends ReaderIo
{
    static SerialTranceiver mSerial = new SerialTranceiver();
    static public boolean opened = false;

    public void TransmitData(byte[] data, int length) throws RcpException
    {
	mSerial.send(data, length);
    }

    public void setOnBytesAvailableListener(OnBytesAvailableListener listener)
    {
	mSerial.registerBytesAvailableListener(listener);
    }

    public void open() throws RcpException
    {
	if (opened == true)
	{
	    RcpException exception = new RcpException("fail: already opened",
		    RcpConst.SERIAL_OPEN_FAIL);
	    throw exception;
	}
	
	opened = mSerial.open();
    }

    public void close() throws RcpException
    {
	if (opened == true)
	    mSerial.close();
	    
	opened = false;
    }
}
